<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<section class="content">
    <div class="row" style="margin-bottom: 24px">

        <button type="button" class="btn btn-success pull-right" id="btn-receive" style="margin-left: 10px"
                onclick="selected()" shiro:hasPermission="tec:batchRecep:edit">
            <span class="Bold">接收</span>
        </button>
        <a class="btn btn-info pull-right" id="btn-select" th:href= "@{/craft/receive/only/selectAll(id=${serviceTaskModel.id},proCode=${serviceTaskModel.proCode})}" target="_blank">
            <span class="Bold">查看完整清单</span>
        </a>
    </div>
    <div class="row">
        <form id="sheetForm" class="form-horizontal">
            <div class="col-xs-11 col-xs-offset-1">
                <input type="hidden" name="makeSheetId" th:value="${serviceTaskModel.id}" id="makeSheetId">
                <table class="t1 t3">
                    <thead>
                    <tr>
                        <td colspan="15">
                            <img th:src="@{/img/logo3.jpg}" width="64px" height="40px" style="margin-top: -30px">
                            <div style="display: inline-block;margin-top: 5px;margin-left: 20px">
                                <span style="letter-spacing: 24px;display: block;line-height: 20px">&nbsp;辽宁忠旺机械设备制造有限公司</span>
                                <span style="display: block;font-size: 12px;line-height: 20px">Liaoning Zhongwang Machinery Equipment Manufacturing Co., Ltd</span>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="15" style="font-size: 16px;letter-spacing: 4px;">
                            制作件清单变更单
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td colspan="3" style="width: 8%">项目编号</td>
                        <td style="width: 11%;font-size: 14px;">
                            <input id="sheetForm-proCode" type="text" class="form-control" name="proCode"
                                   th:value="${serviceTaskModel.proCode}" readonly>
                        </td>
                        <td style="width: 8%">项目名称</td>
                        <td colspan="4" style="width: 21%">
                            <input id="sheetForm-proName" type="text" class="form-control" name="proName"
                                   th:value="${serviceTaskModel.proName}" readonly>
                        </td>
                        <td style="width: 8%">项目数量</td>
                        <td style="width: 6%">
                            <input id="sheetForm-proNum" type="number" class="form-control" name="proNum"
                                   th:value="${serviceTaskModel.proNum}" readonly>
                        </td>
                        <td style="width: 6%">类型</td>
                        <td style="width: 9%">
                            <input id="sheetForm-malType" type="text" class="form-control" name="special"
                                   th:value="${serviceTaskModel.special}" readonly>
                            <input id="sheetForm-specialId" type="hidden" th:value="${serviceTaskModel.specialId}" name="specialId">
                        </td>
                        <td style="width: 6%">部分</td>
                        <td style="width: 9%">
                            <input id="sheetForm-part" type="text" class="form-control error" name="part"
                                   th:value="${serviceTaskModel.part}" readonly>
                            <input id="sheetForm-partId" type="hidden" th:value="${serviceTaskModel.partId}" name="partId">
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td style="width: 4%">序号</td>
                        <td colspan="3">图号</td>
                        <td colspan="3">图名</td>
                        <td style="width: 6%">数量</td>
                        <td colspan="1">制作件类型</td>
                        <td colspan="1">操作类型</td>
                        <td colspan="2">备注</td>
                        <td colspan="2"> 变更原因</td>
                        <td></td>
                    </tr>
                    </thead>
                    <tbody id="out">
                    <tr th:each="plan : ${makePlans}" trType="sourceTR" th:teId="${plan.id}">
                        <td th:if="${planStat.index == 0}" th:rowspan="${planStat.size}">变更前</td>
                        <td th:text="${planStat.count}" beforeTdOrdernum="beforeTdOrdernum"></td>
                        <td colspan="3" th:text="${ plan.drawNo}"></td>
                        <td colspan="3" th:text="${plan.drawName}"></td>
                        <td th:text="${plan.drawNum}"></td>
                        <td colspan="1" th:text="${ plan.makeType}"></td>
                        <td colspan="1"></td>
                        <td colspan="2" th:text="${plan.remark}"></td>
                        <td colspan="2"></td>
                        <td></td>


                    </tr>
                    <tr th:each="plan : ${makePlans}" trType="sourceTR" th:teId="${plan.id}">
                        <td th:if="${planStat.index == 0}" th:rowspan="${planStat.size}">变更后</td>
                        <td th:text="${planStat.count}" beforeTdOrdernum="beforeTdOrdernum"></td>
                        <td colspan="3" th:text="${ plan.afterDrawNo}"></td>
                        <td colspan="3" th:text="${plan.afterDrawName}"></td>
                        <td th:text="${plan.afterDrawNum}"></td>
                        <td colspan="1" th:text="${ plan.afterMakeType}"></td>
                        <td colspan="1" th:text="${plan.technologyChange==3?'新增': (plan.technologyChange==2?'删除': (plan.technologyChange==1?'修改':''))}"></td>
                        <td colspan="2" th:text="${plan.afterRemark}"></td>
                        <td colspan="2" th:text="${plan.changeReason}"></td>
                        <td></td>

                    </tr>
                    </tbody>
                </table>
            </div>
        </form>
    </div>
    <!--<div th:include="include :: tip"></div>-->
</section>
<div th:include="include :: footer"></div>
<script th:src="@{/plugin/SheetJs/xlsx.core.min.js}"></script>
<script th:inline="javascript">
    let tempUrl, trAutoIndex = 9999, dynamicId = 0, orderNum;

    /** 计算表格序号 */
    // function computerNo() {
    //     $("table tbody tr").each(function (i, e) {
    //         $(this).children("td:first").text(i + 1);
    //     });
    // }


    /** tr表格变更后的序号的计算*/
    function beforeCompuTrNo() {
        $("table tbody tr[trtype='sourceTR']").each(function (i, e) {
            $(this).children("td[beforeTdOrdernum='beforeTdOrdernum']").text(i + 1);
        })
    }

    /** tr表格变更前的序号的计算*/
    function afterCompuTrNo() {
        $("table tbody tr[trtype='cloneTR']").each(function (i, e) {
            $(this).children("td[afterTdOrdernum='afterTdOrdernum']").text(i + 1);
        })
    }

    /** 选择计划 */
    function selected() {
        js.modal.confirm("确定要接收当前单据吗?", function () {
            let makeSheetId = $("#makeSheetId").val();
            js.post({
                // url:  ctx + 'craft/receive/receiveCard?ids='+arr,
                url: ctx + 'craft/receive/only/receiveCard',
                data: {id: makeSheetId, sheetType: 2},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        window.history.go(-1);
                        // js.modal.success(result.msg);
                        // js.table.refresh(table);

                    } else {
                        js.modal.success("请先接收原始单据在接收变更单！！");
                        // js.modal.warning(result.msg);

                    }
                    js.modal.closeLoading();
                    // location.reload();刷新本页
                }
            })
        });
    }

    function selecteAll() {

        let makeSheetId = $("#makeSheetId").val();

        var proCode = $("#sheetForm-proCode").val();
        var  specialId= $("#sheetForm-specialId").val();
        var partId = $("#sheetForm-partId").val();
        js.post({
            // url:  ctx + 'craft/receive/receiveCard?ids='+arr,
            url: ctx + 'craft/receive/only/selectAll',
            data: {id: makeSheetId,proCode: proCode, specialId: specialId,partId:partId},
            success: function (result) {
                window.open("")
            }
        })
    }


    $(function () {
        if([[${serviceTaskModel.receiveStatus}]]==1){
            document.getElementById("btn-receive").style.display="none";
        }


        /** 添加一行 */
        $("#sheetForm").on('click', '.out-add', function () {
            /** 动态添加《td》的记录数*/
            trAutoIndex++;
            /** 动态添加下拉列表的记录数*/
            dynamicId++;
            /** 添加没行数据时获得当前行数下的orderNum*/
            orderNum = $(this).parents("tr").attr("orderNumId")
            var indexTr = $(this).parents("tr").attr("teid");
            beforeCompuTrNo();


            afterCompuTrNo();
            rowspanesAdd();
            additional();
        });


    });
</script>
</body>
</html>
